<?php
abstract class db
{
	# Connection
	public static function connect($host, $user, $pass)
	{
		return @mysql_connect($host, $user, $pass);
	}
	
	public static function error_key()
	{
		switch(mysql_errno())
		{
			case 2002:
				return 'invalid_host';
			case 1044:
				return 'access_denied';
		}
	}
	
	# Database
	public static function select_db($name)
	{
		return @mysql_select_db($name);
	}
	
	# Query
	public static function query($string, $error=true)
	{
		$query = mysql_query($string);
		
		if(!$query && $error)
		{
			fw::db_error();
		}
		
		return $query;
	}
	
	# Fetching
	public static function fetch($query, $type='assoc')
	{
		$fetch = 'mysql_fetch_'.$type;
		
		return $fetch($query);
	}
	
	# Row number
	public static function num_rows($query)
	{
		return mysql_num_rows($query);
	}
	
	# Last inserted id
	public static function last_id()
	{
		return mysql_insert_id();
	}
	
	# Error
	public static function error()
	{
		return mysql_error();
	}
	
	# Escape
	public static function escape($string)
	{
		return mysql_real_escape_string($string);
	}
}